//
//  EmoticonViewModel.swift
//  表情键盘
//
//  Created by 吴婷婷 on 15/11/15.
//  Copyright © 2015年 wutingting. All rights reserved.
//

import Foundation
class EmoticonManager {
    ///单例
    static let sharedManager = EmoticonManager()
    
    //表情包数组
    lazy var packages = [EmoticonPackage]()
    
    private init() {
        //添加最近数组
        packages.append(EmoticonPackage(dict: ["group_name_cn": "最近A"]))
        //加载表情包数据
        guard let path = NSBundle.mainBundle().pathForResource("emoticons", ofType: "plist", inDirectory: "Emoticons.bundle") else {
            print("加载文件不存在")
            return
        }
        
        guard let dict = NSDictionary(contentsOfFile: path) else {
            print("加载文件出错")
            return
        }
        
        let array = (dict["packages"] as! NSArray).valueForKey("id") as! [String]
        
        for id in array {
            loadInfoPlist(id)
        }
        
    }
    
    private func loadInfoPlist(id: String) {

        let path = NSBundle.mainBundle().pathForResource("info", ofType: "plist", inDirectory: "Emoticons.bundle/\(id)")
        
        let dict = NSDictionary(contentsOfFile: path!) as! [String: AnyObject]
        
        packages.append(EmoticonPackage(dict: dict))
        
    }
}
